package br.com.mumakgnod.engine;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.util.ArrayList;

import javax.swing.JPanel;


public class GameGridJPanel extends JPanel implements GameGrid {
	private static final long serialVersionUID = 671277543680936327L;
	private Graphics2D canvas;
	
	private ArrayList<SpriteJFrame> sprites;
	
	public GameGridJPanel() {
		sprites = new ArrayList<SpriteJFrame>();
	}
	
	public void setCanvas(Graphics2D canvas) {
		System.out.println("canvas: "+canvas);
		this.canvas = canvas;
		setHints();
	}
	
	private void setHints() {
		this.canvas.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	}
	
	public void paint(Graphics g) {
		setCanvas((Graphics2D) g);
		onDraw();
	}
	
	public Graphics2D getCanvas() {
		return this.canvas;
	}
	
	public void addSprite(SpriteJFrame sprite) {
		sprites.add(sprite);
	}

	public void onDraw() {
		for (SpriteJFrame sprite : sprites) {
			sprite.onDraw(getCanvas(), 150, 150);
		}
		canvas.dispose();
	}

	@Override
	public int getSizeX() {
		return (int) this.getWidth();
	}

	@Override
	public int getSizeY() {
		return (int) this.getHeight();
	}

}
